package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 字数限制实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：word_limit
 *
 * 根据B-02-03-07简答题管理子模块设计文档实现
 * 管理简答题的字数限制信息，支持多种限制类型和灵活配置。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "word_limit")
@Comment("字数限制表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WordLimit {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 字数限制唯一标识符
     */
    @NotBlank(message = "字数限制ID不能为空")
    @Size(max = 50, message = "字数限制ID长度不能超过50个字符")
    @Column(name = "limit_id", nullable = false, length = 50, unique = true)
    private String limitId;

    /**
     * 关联的简答题ID
     */
    @NotBlank(message = "题目ID不能为空")
    @Column(name = "question_id", nullable = false, unique = true)
    private String questionId;

    /**
     * 限制类型（MIN-最少字数，MAX-最多字数，RANGE-范围字数，EXACT-精确字数）
     */
    @NotBlank(message = "限制类型不能为空")
    @Size(max = 20, message = "限制类型长度不能超过20个字符")
    @Column(name = "limit_type", nullable = false, length = 20)
    private String limitType;

    /**
     * 最少字数
     */
    @Column(name = "min_words")
    private Integer minWords;

    /**
     * 最多字数
     */
    @Column(name = "max_words")
    private Integer maxWords;

    /**
     * 精确字数
     */
    @Column(name = "exact_words")
    private Integer exactWords;

    /**
     * 字数范围描述
     */
    @Size(max = 50, message = "字数范围描述长度不能超过50个字符")
    @Column(name = "range_description", length = 50)
    private String rangeDescription;

    /**
     * 是否启用字数检查
     */
    @NotNull(message = "字数检查设置不能为空")
    @Column(name = "enable_check", nullable = false)
    private Boolean enableCheck;

    /**
     * 是否严格要求
     */
    @NotNull(message = "严格要求设置不能为空")
    @Column(name = "is_strict", nullable = false)
    private Boolean isStrict;

    /**
     * 容差范围（允许的误差范围）
     */
    @Column(name = "tolerance")
    private Integer tolerance;

    /**
     * 超出限制的处理方式（WARNING-警告，ERROR-错误，AUTO_ADJUST-自动调整）
     */
    @Size(max = 20, message = "处理方式长度不能超过20个字符")
    @Column(name = "exceed_handling", length = 20)
    private String exceedHandling;

    /**
     * 字数统计方式（CHAR-字符数，WORD-单词数，CHINESE_CHAR-中文字符数）
     */
    @Size(max = 20, message = "统计方式长度不能超过20个字符")
    @Column(name = "counting_method", length = 20)
    private String countingMethod;

    /**
     * 排除内容（不参与字数统计的内容，如标点符号）
     */
    @Column(name = "excluded_content", columnDefinition = "TEXT")
    private String excludedContent;

    /**
     * 包含要求（必须包含的内容类型）
     */
    @Column(name = "inclusion_requirements", columnDefinition = "TEXT")
    private String inclusionRequirements;

    /**
     * 提示信息
     */
    @Column(name = "hint_message", columnDefinition = "TEXT")
    private String hintMessage;

    /**
     * 错误提示信息
     */
    @Column(name = "error_message", columnDefinition = "TEXT")
    private String errorMessage;

    /**
     * 是否显示实时字数
     */
    @NotNull(message = "实时字数显示设置不能为空")
    @Column(name = "show_realtime_count", nullable = false)
    private Boolean showRealtimeCount;

    /**
     * 字数限制状态（ACTIVE-激活，INACTIVE-非激活，DEPRECATED-已废弃）
     */
    @NotBlank(message = "字数限制状态不能为空")
    @Size(max = 20, message = "字数限制状态长度不能超过20个字符")
    @Column(name = "limit_status", nullable = false, length = 20)
    private String limitStatus;

    /**
     * 是否激活
     */
    @NotNull(message = "激活状态不能为空")
    @Column(name = "is_active", nullable = false)
    private Boolean isActive;

    /**
     * 版本号
     */
    @NotNull(message = "版本号不能为空")
    @Column(name = "version_number", nullable = false)
    private Integer versionNumber;

    /**
     * 创建者ID
     */
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;
}